﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMatrix.WebData;

using AesApplication.Models;

namespace AesApplication.Controllers
{
    [Authorize]
    public class HiringSpecialistController : Controller
    {
        private AesContext db = new AesContext();

        public ActionResult Index()
        {
            HiringSpecialistIndexViewModel model = new HiringSpecialistIndexViewModel
            {
                Departments = db.DepartmentsAssignedTo(WebSecurity.CurrentUserId),
            };
            
            return View(model);
        }


        public ActionResult InterviewGrid(int id)
        {
            Job job = db.Jobs.Find(id);

            return View(job);
        }

        [HttpPost]
        public ActionResult UpdateApplication(string submit, string comment, int id, string specialist)
        {
            Application app = db.Applications.Find(id);

            switch(submit.ToLower())
            {
                case "approve":
                    app.Status = ApplicationStatus.AwaitingHire;
                    app.HiringSpecialist = specialist;
                    app.HiringSpecialistComment = comment;
                    db.SaveChanges();
                    break;
                case "discard":
                    app.Status = ApplicationStatus.HumanRejected;
                    app.HiringSpecialist = specialist;
                    app.HiringSpecialistComment = comment;
                    db.SaveChanges();
                    break;
                case "save":
                    app.HiringSpecialist = specialist;
                    app.HiringSpecialistComment = comment;
                    db.SaveChanges();
                    break;
            }

            return RedirectToAction("Index", "HiringSpecialist");
        }
        
        public ActionResult Interview(int id)
        {
            Application app = db.Applications.Find(id);
            if (app == null)
            {
                return HttpNotFound();
            }

            return View(app);
        }
	}
}